package com.ygqh.baby.service.wechat.model;

import com.foxinmy.weixin4j.mp.model.QRParameter;
import com.foxinmy.weixin4j.type.QRType;

import java.io.Serializable;

/**
 * @author: sunshuo
 * @date: 2018/12/26 15:46
 */
public class WxQRParameter implements Serializable {

	private static final long serialVersionUID = -8711266636564446077L;

	/**
	 * 临时二维码的有效时间, 最大不超过2592000（即30天），此字段如果不填，则默认有效期为30秒
	 */
	private int expireSeconds;
	/**
	 * 二维码类型
	 *
	 * @see com.foxinmy.weixin4j.type.QRType
	 */
	private QRType qrType;
	/**
	 * 场景值I 根据qrType参数而定
	 */
	private String sceneValue;

	private WxQRParameter() {
	}

	public int getExpireSeconds() {
		return expireSeconds;
	}

	public QRType getQrType() {
		return qrType;
	}

	public String getSceneValue() {
		return sceneValue;
	}

	private String content;

	public String getContent() {
		return content;
	}

	/**
	 * 创建临时二维码(场景值为string)
	 *
	 * @param expireSeconds
	 *            有效时间
	 * @param sceneValue
	 *            二维码的场景值
	 * @return 二维码参数
	 */
	public static WxQRParameter createTemporary(int expireSeconds, String sceneValue) {
		WxQRParameter qr = new WxQRParameter();
		qr.qrType = QRType.QR_SCENE;
		qr.expireSeconds = expireSeconds;
		qr.sceneValue = sceneValue;
		qr.content = String
				.format("{\"expire_seconds\": %s, \"action_name\": \"%s\", \"action_info\": {\"scene\": {\"scene_str\": %s}}}",
						expireSeconds, QRType.QR_SCENE.name(), sceneValue);
		return qr;
	}

	@Override
	public String toString() {
		return "QRParameter [expireSeconds=" + expireSeconds + ", qrType="
				+ qrType + ", sceneValue=" + sceneValue + "]";
	}
}
